#include <stdio.h>
#include <string.h>	// strcmp
#include <ctype.h>	// isdigit
#include <stdlib.h>	// atoi
#include <dirent.h>	// opendir

static int get_nvmem_index(void)
{
	const char *path = "/sys/devices/platform/soc/243000.efuse/";
	const char *prefix = "nvmem";
	int prefix_len = strlen(prefix);
	DIR *efuse_dir = opendir(path);
	struct dirent *entry;
	const char *pos;

	if (!efuse_dir) {
		printf("Failed to open directory: %s\n", path);
		return -1;
	}

	while ((entry = readdir(efuse_dir))) {
		if (strncmp(entry->d_name, prefix, prefix_len))
			continue;

		pos = entry->d_name + prefix_len;

		if (isdigit(*pos)) {
			closedir(efuse_dir);
			return atoi(pos);
		}
	}

	return -1;
}

int main(int argc, const char *argv[])
{
	printf("TODO:\n");

	return 0;
}

